package com.qidianit.mes.pro.controller;

import com.github.pagehelper.PageInfo;
import com.qidianit.mes.pojo.Result;
import com.qidianit.mes.pojo.WorkflowProcess;
import com.qidianit.mes.pro.service.WorkflowProcessService;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ Description:
 * @ Author:WuJingLei
 * @ Date: 2025/9/18 -19:33
 */
@RestController
@RequestMapping("/workflowProcess")
public class WorkflowProcessController {
    @Autowired
    private WorkflowProcessService workflowProcessService;

    @GetMapping("/page")
    public Result page(Long workflowId,
                                                  @RequestParam(defaultValue = "1")int page,
                                                  @RequestParam(defaultValue = "10")int size){
        if (workflowId == null){
            return Result.error(500,"工艺id不能为空",null);
        }
        return workflowProcessService.queryList(workflowId,page,size);
    }

    @PostMapping("add")
    public Result add(@RequestBody WorkflowProcess workflowProcess){
        return workflowProcessService.addWorkflowProcess(workflowProcess);
    }

    @GetMapping("/{id}")
    public Result<WorkflowProcess> getById(@PathVariable Long id){
        return workflowProcessService.getById(id);
    }

    @PutMapping("/update")
    public Result update(@RequestBody WorkflowProcess workflowProcess){
        return workflowProcessService.updateWorkflowProcess(workflowProcess);
    }

    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Long id){
        return workflowProcessService.deleteWorkflowProcessById(id);
    }

    @DeleteMapping("/batchDelete")
    public Result batchDelete(Long[] id){
        return workflowProcessService.batchDeleteWorkflowProcess(id);
    }
}
